package ex404.manager;

import java.util.Date;
import java.util.Objects;

public class Product implements Comparable<Product>, Cloneable {
    private String id;
    private String name;
    private double price;
    private int quantity;
    private Date launchDate;

    public Product() {
    }

    public Product(String id, String name, double price, int quantity, Date launchDate) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.quantity = quantity;
        this.launchDate = launchDate;
    }

    @Override
    public int compareTo(Product other) {
        return this.id.compareTo(other.id);
    }

    @Override
    public Object clone() {
        try {
            Product temp = (Product) super.clone();
            temp.launchDate = (Date) this.launchDate.clone();
            return temp;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return id.equals(product.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    // set & get ---------------
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Date getLaunchDate() {
        return launchDate;
    }

    public void setLaunchDate(Date launchDate) {
        this.launchDate = launchDate;
    }
}
